<?php
/**
 * Created by PhpStorm.
 * User: xuic
 * Date: 2016/7/3
 * Time: 9:48
 */

namespace admin;

use C\lib\Db;
use C\lib\Sql;

use C\mod\finance;
use C\mod\auth;

class finances extends ctr
{

    const listRows = 20;   // 每页显示的几条记录

    private static $centerPoint=[179, 373]; // 天津分拨中心
    private static $center_price = 0.8;// 分拨中心收取站点1的费用

    private static $leiniao35_id = 284;
    private static $leiniao35 = 3.5; // 雷鸟收费3.5元

    private static $leiniao7_id = 285;
    private static $leiniao7 = 7; // 雷鸟收费7元

    public static $unit_price = 1.5;// 站点2收取站点1的费用

    // 西青公司	191, 东丽一公司	188,东丽二公司	189, 万达公司	187, 华苑公司	190, 南开		253
    private static $special_points = [191,188,189,187,190,253];
    public static $unit_price2 = 3;// 指定站点2收取站点1的费用


    // --- 报表/财务 ---
    public function main()
    {

        if($worker = $this->getLogAds()) {

            if(finances::canReportFinance()) {

                isset($_GET['wid']) && trim($_GET['wid']) ? $search = ' and cdw.id=' . $_GET['wid'] : $search = '';
                isset($_GET['wname']) && trim($_GET['wname']) ? $search .= ' and realname like "%' . $_GET['wname'] . '%" ' : '';

                if($aFlag = finances::canQueryAllFinances()) {

                    $stmt = Db::query('select cdw.id workerId,realname, balance ,cdf.time_update time_update ,cdc.name cityName from cd_finance cdf , cd_worker cdw left join cd_city cdc on cdw.city_id=cdc.id  where cdf.worker_id=cdw.id ' . $search);
                }else {
                    $stmt = Db::query('select cdw.id workerId,realname, balance ,cdf.time_update time_update ,cdc.name cityName from cd_finance cdf , cd_worker cdw left join cd_city cdc on cdw.city_id=cdc.id  where cdf.worker_id=cdw.id and cdf.worker_id='.$worker->id . $search);
                }

                $datas = [];
                if($stmt && $stmt->rowCount()) {

                    while($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                        $datas[] = $data;
                    }
                }

                $flag = finances::canPrepaid(); // 是否能充值

                $this->render('finances/main', ['datas' => $datas ,'aqflag'=>$aFlag, 'flag'=>$flag]);

            } else
                $this->render('user1/main',['err'=>'无此操作权限']);
        } else
            $this->render('user1/main',['err'=>'请先登陆']);

    }


    public function financesDetail()
    {
        if($worker = $this->getLogAds()) {

                if(isset($_GET['wid']) && trim($_GET['wid']) != '' && isset($_GET['wname']) && trim($_GET['wname']) != '') {

                    if(($aqflag=\admin\finances::canQueryAllFinances()) || $_GET['wid'] == $worker->id) {

                    $search = isset($_GET['searchDate']) ? ' having days="'.$_GET['searchDate'].'"':'';

                    $stmt1 = Db::query("select count(id) count from (select id,count(id) counts,FROM_UNIXTIME(time_add,'%Y-%m-%d') days from cd_finance_details where worker_id={$_GET['wid']}  group by days  ".$search.") as a ");

                    if($stmt1 && $stmt1->rowCount()) {
                        $data1 = $stmt1->fetch(\PDO::FETCH_ASSOC);
                        $count = $data1['count'];

                        if($count) {
                            // --- 判断分页 ---
                            $page = isset($_GET['page']) && trim($_GET['page']) != '' ? intval($_GET['page']) : 1;

                            \C\lib\Page::setParam($count, self::listRows, $page, 10);
                            \C\lib\Page::setConfig('prev', '<<');
                            \C\lib\Page::setConfig('next', '>>');
                            \C\lib\Page::setConfig('first', '首页');
                            \C\lib\Page::setConfig('last', '尾页');
                            \C\lib\Page::setConfig('theme', "共 %TOTAL_ROW% 条记录( %NOW_PAGE% / %TOTAL_PAGE% 页) %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");


                            $limit1 = ( $page-1) * self::listRows;

                            $stmt = Db::query("select id,FROM_UNIXTIME(time_add,'%Y-%m-%d') days,sum(price) totalPrice from cd_finance_details where worker_id={$_GET['wid']}  group by days  ".$search." ORDER BY days DESC LIMIT ".$limit1.',' . self::listRows);



                            if($stmt && $stmt->rowCount()) {
                                $datas = [];
                                while($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                                    $datas[] = $data;
                                }


                                $this->render('finances/financeDetail',[
                                        'aqflag'=>$aqflag,
                                        'realname'=>$_GET['wname'],
                                        'datas'=>$datas,
                                        'pages' => \C\lib\Page::show(),
                                        'centerPrice'=>static::$center_price
                                ]);
                            }else
                                $this->render('finances/financeDetail', ['errors' => '查无该用户财务详情组或失败']);
                        }else
                            $this->render('finances/financeDetail', ['errors' => '查无该用户财务详情']);
                    }else
                        $this->render('finances/financeDetail', ['errors' => '统计财务详情表失败']);
                } else
                    $this->render('finances/financeDetail',['errors'=>'只能查看自己的财务详情']);
            } else
                $this->render('finances/financeDetail', ['errors' => '查询参数传递错误']);
        } else
            $this->render('user1/main',['err'=>'请先登陆']);
    }


    // 各工作人员每日具体统计
    public function queryEveryDate() {

        if($worker = $this->getLogAds()) {
            if(isset($_POST['fdate']) && trim($_POST['fdate']) != '' && isset($_POST['wid']) && trim($_POST['wid']) != '') {

                list($y, $m, $d) = explode('-', $_POST['fdate']);

                if(checkdate($m ,  $d , $y )) {

                    date_default_timezone_set('PRC');
                    $startTime = strtotime($y.'-'.$m.'-'.$d.' 0:0:0');
                    $endTime = strtotime($y.'-'.$m.'-'.$d.' 23:59:59');

                    $scan_type = (in_array($_POST['wid'] ,static::$centerPoint )) ? 1 : 0;

                    $stmt1 = Db::query("select * from
                                      (select count(distinct piece_id) as getNum from cd_piece_state where worker_id={$_POST['wid']} and state_in=3 and (time_add>{$startTime} and time_add<={$endTime})) a,
                                      (select if(isNull(sum(piece_count)),0,sum(piece_count)) as sendNum from cd_finance_details where worker_id={$_POST['wid']} and scan_type=2 and (time_add>{$startTime} and time_add<={$endTime})) bdUser,
                                      (select if(isNull(sum(price)),0,sum(price)) as center_charge from cd_finance_details where worker_id={$_POST['wid']}  and scan_type={$scan_type} and (time_add>{$startTime} and time_add<={$endTime})) g,
                                      (select if(isNull(sum(piece_count)),0,sum(piece_count)) as totalNum from cd_finance_details where worker_id={$_POST['wid']} and (time_add>{$startTime} and time_add<={$endTime}) and scan_type={$scan_type}) c,
                                      (select if(isNull(sum(price)),0,sum(price)) allPerPrice from cd_finance_details where  worker_id={$_POST['wid']} and (time_add>{$startTime} and time_add<={$endTime})) e,
                                      (select if(isNull(sum(price)),0,sum(price)) transfer_charge from cd_finance_details where  worker_id={$_POST['wid']} and scan_type=3 and (time_add>{$startTime} and time_add<={$endTime})) f,
                                      (select if(isNull(sum(price)),0,sum(price)) prepaid_charge from cd_finance_details where  worker_id={$_POST['wid']} and scan_type=4 and (time_add>{$startTime} and time_add<={$endTime})) h");//'3' => '已集散', '9' => '到集散',


                    if($data = $stmt1->fetch(\PDO::FETCH_ASSOC)) {
                        // 中心扫描费＝收件数量×1.5元
                        // 派件费=派件数量×1元
                        if(in_array($_POST['wid'],static::$special_points)) {
                            $data['send_charge'] = bcmul($data['sendNum'], static::$unit_price2,1);
                        }else if($worker->id == static::$leiniao35_id){
                            $data['send_charge'] = bcmul($data['sendNum'], static::$leiniao35,1);
                        }else if($worker->id == static::$leiniao7_id){
                            $data['send_charge'] = bcmul($data['sendNum'], static::$leiniao7,1);
                        }else{
                            $data['send_charge'] = bcmul($data['sendNum'], static::$unit_price,1);
                        }

                        $data['flag'] = in_array($worker->id ,static::$centerPoint);
                        // 中转费（站点）＝   $data['transfer_charge']



                        $this->writeJson( 1 , ['jdatas'=> $data,'date'=>$_POST['fdate']] , 1);
                    }else
                        $this->writeJson( 0 , '获取失败' , 1);
                }else
                    $this->writeJson( 0 , '无效日期格式，正确示例：2016-10-21' ,1 );
            }else
                $this->writeJson( 0 , '无查询财务参数传递' ,1 );
        } else
            $this->writeJson( 0 , '请先登陆' ,1 );

    }


    // --- 派件列表 ---
    public function sendList() {
        if($worker = $this->getLogAds()) {
            if(isset($_POST['fdate']) && trim($_POST['fdate']) != '' && isset($_POST['wid']) && trim($_POST['wid']) != '') {

                list($y, $m, $d) = explode('-', $_POST['fdate']);

                if(checkdate($m ,  $d , $y )) {

                    date_default_timezone_set('PRC');
                    $startTime = strtotime($y . '-' . $m . '-' . $d . ' 0:0:0');
                    $endTime = strtotime($y . '-' . $m . '-' . $d . ' 23:59:59');
                    //派件列表
                    $stmt = Db::query("select piece_count,cdfd.worked_id worked_id,a.realnames realnames,price,piece_count, piece_ids from cd_finance_details cdfd,(select cdfd.worked_id worked_id,group_concat(distinct realname) realnames from cd_finance_details cdfd,cd_worker cdw where find_in_set(cdw.id,cdfd.worked_id) group by cdfd.worked_id) as a where a.worked_id=cdfd.worked_id and worker_id={$_POST['wid']} and time_add>{$startTime} and time_add<={$endTime} and scan_type=2");

                    $sendList = [];
                    if($stmt && $stmt->rowCount()) {
                        while($data2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                            $sendList[] = $data2;
                        }
                    }
                    $this->writeJson(1, ['date'=>$_POST['fdate'], 'sendList' => $sendList], 1);
                }else
                    $this->writeJson( 0 , '无效日期格式，正确示例：2016-10-21' ,1 );
            }else
                $this->writeJson( 0 , '无查询派件参数传递' ,1 );
        } else
            $this->writeJson( 0 , '请先登陆' ,1 );
    }


    //根据件ID集返回件码
    public function queryPieceCode() {

        if($worker = $this->getLogAds()) {

            if(isset($_POST['pids']) && trim($_POST['pids']) != '' ) {

                $stmt = Db::query('select piece_code from cd_order_piece where id in ('.$_POST['pids'].')');
                $pieceCodes = '';

                if($stmt && $stmt->rowCount()) {
                    while($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                        $pieceCodes .= $data['piece_code'].' , ';
                    }
                }

                $pieceCodes = trim($pieceCodes,' , ');
                $this->writeJson(1, ['pieceCodes'=>$pieceCodes], 1);

            }else
                $this->writeJson( 0 , '无查询件ID集参数传递' ,1 );
        }else {
            $this->writeJson( 0 , '请先登陆' ,1 );
        }
    }


    // --- 中转件列表 ---
    public function tranferList() {

        if($worker = $this->getLogAds()) {

            if(isset($_POST['fdate']) && trim($_POST['fdate']) != '' && isset($_POST['wid']) && trim($_POST['wid']) != '') {

                list($y, $m, $d) = explode('-', $_POST['fdate']);

                if(checkdate($m ,  $d , $y )) {

                    date_default_timezone_set('PRC');
                    $startTime = strtotime($y . '-' . $m . '-' . $d . ' 0:0:0');
                    $endTime = strtotime($y . '-' . $m . '-' . $d . ' 23:59:59');
                    //派件列表
                    $stmt = Db::query("select cdf.worked_id worked_id,realname,sum(price) price ,sum(piece_count) piece_count,group_concat(piece_ids) piece_ids from cd_finance_details cdf , cd_worker cdw where cdw.id=cdf.worked_id and  worker_id={$_POST['wid']} and cdf.time_add>{$startTime} and cdf.time_add<={$endTime} and scan_type=3 group by cdf.worked_id");
                    $tranferList = [];
                    if($stmt && $stmt->rowCount()) {
                        while($data2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                            $tranferList[] = $data2;
                        }
                    }
                    $this->writeJson(1, ['date'=>$_POST['fdate'], 'tranferList' => $tranferList], 1);
                }else
                    $this->writeJson( 0 , '无效日期格式，正确示例：2016-10-21' ,1 );
            }else
                $this->writeJson( 0 , '无查询中转件参数传递' ,1 );
        } else
            $this->writeJson( 0 , '请先登陆' ,1 );
    }


    // --- 充值详情列表 ---
    public function prepaidList() {

        if($worker = $this->getLogAds()) {
            if(isset($_POST['fdate']) && trim($_POST['fdate']) != '' && isset($_POST['wid']) && trim($_POST['wid']) != '') {

                list($y, $m, $d) = explode('-', $_POST['fdate']);

                if(checkdate($m ,  $d , $y )) {

                    date_default_timezone_set('PRC');
                    $startTime = strtotime($y . '-' . $m . '-' . $d . ' 0:0:0');
                    $endTime = strtotime($y . '-' . $m . '-' . $d . ' 23:59:59');
                    //派件列表
                    $stmt = Db::query("select cdf.worked_id worked_id,realname,price,FROM_UNIXTIME(cdf.time_add,'%Y-%m-%d %H-%i-%s') time_add from cd_finance_details cdf , cd_worker cdw where cdw.id=cdf.worked_id and  worker_id={$_POST['wid']} and cdf.time_add>{$startTime} and cdf.time_add<={$endTime} and scan_type=4");

                    $tranferList = [];
                    if($stmt && $stmt->rowCount()) {
                        while($data2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                            $tranferList[] = $data2;
                        }
                    }
                    $this->writeJson(1, ['date'=>$_POST['fdate'], 'prepaidList' => $tranferList], 1);
                }else
                    $this->writeJson( 0 , '无效日期格式，正确示例：2016-10-21' ,1 );
            }else
                $this->writeJson( 0 , '无查询充值参数传递' ,1 );
        } else
            $this->writeJson( 0 , '请先登陆' ,1 );
    }


    // 判断是否有充值权限
    public function canPrepaid() {

        if($worker = $this->getLogAds()) {

            $stmt = Db::prepare('select id from cd_auth where name="' . strtr(__METHOD__, '\\', '/') . '" and find_in_set(' . $worker->id . ', worker_ids)');

            if(($stmt->execute()) && $stmt->rowCount() > 0) {
                return true;
            }else
                return false;
        } else {
            return false;
        }
    }

    // 判断是否有查看所有财务列表权限
    public function canQueryAllFinances() {

        if($worker = $this->getLogAds()) {

            $stmt = Db::prepare('select id from cd_auth where name="' . strtr(__METHOD__, '\\', '/') . '" and find_in_set(' . $worker->id . ', worker_ids)');

            if(($stmt->execute()) && $stmt->rowCount() > 0) {
                return true;
            }else
                return false;
        } else {
            return false;
        }
    }


    // --- 充值 ---
    public function doPrepaid() {
        if($worker = $this->getLogAds()) {

            if(isset($_POST['inputWid']) && trim($_POST['inputWid'])!='') {
                if(isset($_POST['money']) && is_numeric($_POST['money'])){

                    $pflag = finances::canPrepaid();

                    if($pflag) {


                        if(finance::get(['worker_id'=>$_POST['inputWid']])) {

                            Db::beginTransaction();

                            $pre = Db::prepare('UPDATE cd_finance SET balance=balance+ :money WHERE worker_id= :worker_id');
                            $pre->execute(['money' => $_POST['money'], 'worker_id' => $_POST['inputWid']]);
                            if($pre->rowCount()>0) {

                                $user = new \C\mod\finance_details();
                                $user->set([
                                    'worker_id' => $_POST['inputWid'], //要充值的人ID
                                    'scan_type' => 4, // 表充值
                                    'pay_type' => 0,  // 表正
                                    'price' => $_POST['money'], //充值金额
                                    'status' => 1, //正常
                                    'worked_id' => $worker->id, // 管理员ID，执行充值操作的人ID
                                    'time_add' => $_SERVER['REQUEST_TIME']
                                ]);

                                if($user->create()) {
                                    Db::commit();
                                    $this->writeJson(1, [], 1);
                                }else {
                                    Db::rollBack();
                                    $this->writeJson(0, '更新财务详情表失败', 1);
                                }

                            }else
                                $this->writeJson(0, '更新财务表失败', 1);
                        }else
                            $this->writeJson(0, '无此用户充值信息，用户ID：'.$_POST['inputWid'].'，请联系管理员', 1);
                    } else
                        $this->writeJson(0, '无充值权限', 1);

                }else
                    $this->writeJson( 0 , '无充值金额传入或错误' ,1 );
            }else
                $this->writeJson( 0 , '无充值用户ID传入或错误' ,1 );
        } else
            $this->writeJson( 0 , '请先登陆' ,1 );
    }


    // --- 扫描详情列表 ---
    public function scanList() {

        if($worker = $this->getLogAds()) {

            if(isset($_POST['fdate']) && trim($_POST['fdate']) != '' && isset($_POST['wid']) && trim($_POST['wid']) != '') {

                list($y, $m, $d) = explode('-', $_POST['fdate']);

                if(checkdate($m ,  $d , $y )) {
                    date_default_timezone_set('PRC');
                    $startTime = strtotime($y . '-' . $m . '-' . $d . ' 0:0:0');
                    $endTime = strtotime($y . '-' . $m . '-' . $d . ' 23:59:59');

                    if(in_array($_POST['wid'] , static::$centerPoint)) {
                        //是分拨中心

                        $stmt = Db::query("select piece_count,cdfd.worked_id worked_id,a.realnames realnames,price,piece_count, piece_ids from cd_finance_details cdfd,(select cdfd.worked_id worked_id,group_concat(distinct realname) realnames from cd_finance_details cdfd,cd_worker cdw where find_in_set(cdw.id,cdfd.worked_id) group by cdfd.worked_id) as a where a.worked_id=cdfd.worked_id and worker_id={$_POST['wid']} and time_add>{$startTime} and time_add<={$endTime} and scan_type=1");

                        $scanList = [];
                        if($stmt && $stmt->rowCount()) {
                            while($data2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                                $scanList[] = $data2;
                            }
                        }

                        $this->writeJson(1, ['date'=>$_POST['fdate'], 'scanList' => $scanList], 1);
                    }else {
                        //非分拨中心
                        $stmt = Db::query("select piece_ids from cd_finance_details where time_add>{$startTime} and time_add<={$endTime} and scan_type=1 and worker_id in (".implode(',' , static::$centerPoint).') ');

                        $scanStr = '';
                        if($stmt && $stmt->rowCount()) {
                            while($data2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                                if($data2['piece_ids'])
                                    $scanStr .= ','.strtr($data2['piece_ids'], ['"'=>'', '""'=>'', ',,'=>',']);
                            }
                        }
                        $scanStr = strtr(trim($scanStr,','), [','=>'","']);

                        $stmt = Db::query("select cdo.id id , piece_code,cdp.worker_id worker_id,realname ,cdp.time_add time_add  from cd_order_piece cdo, cd_piece_state cdp,cd_worker cdw where cdw.id=cdp.worker_id and  cdo.id=cdp.piece_id and cdp.state_in=3 and cdp.time_add>{$startTime} and cdp.time_add<={$endTime} and piece_code in(\"".$scanStr.'") order by piece_code ,cdp.time_add desc');

                        $tmpArr = [];
                        if($stmt && $stmt->rowCount()) {

                            while($data2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                                $tmpArr[$data2['piece_code']]['wids'][] = $data2['worker_id'];
                                $tmpArr[$data2['piece_code']]['realname'][] = $data2['realname'];


                            }
                        }

                        $okPieceCode = [];
                        foreach($tmpArr as $k => $v) {
                            foreach($v['wids'] as  $k2 => $v2) {
                                if(in_array($v2, static::$centerPoint)) {
                                    if(isset($v['wids'][$k2 + 1]) && $v['wids'][$k2 + 1] == $_POST['wid']) {
                                        $okPieceCode[$v2]['worked_id']= $v2;
                                        $okPieceCode[$v2]['piece_count']= isset($okPieceCode[$v2]['piece_count'])? ++$okPieceCode[$v2]['piece_count']:1;
                                        $okPieceCode[$v2]['realnames']= $v['realname'][$k2];
                                        if(isset($okPieceCode[$v2]['piece_ids']))
                                            $okPieceCode[$v2]['piece_ids'] .= ' , '.$k;
                                        else
                                            $okPieceCode[$v2]['piece_ids'] =$k;
                                        break;
                                    }
                                } else
                                    continue;
                            }
                        }

                        foreach($okPieceCode as $k=>$v) {
                            $okPieceCode[$k]['price']= -1*bcmul($v['piece_count'] , static::$center_price , 1);
                        }

                        $this->writeJson(1, ['date'=>$_POST['fdate'], 'scanList' => $okPieceCode], 1);
                    }
                }else
                    $this->writeJson( 0 , '无效日期格式，正确示例：2016-10-21' ,1 );
            }else
                $this->writeJson( 0 , '无查询中转件参数传递' ,1 );
        }else
            $this->writeJson( 0 , '请先登陆' ,1 );
    }

    //
    public function ReportPrepaidRecord() {
        if($worker = $this->getLogAds()) {

            if(($aqflag=\admin\finances::canReportPrepaidRecord())) {

                $where[] = isset($_GET['startTime']) && trim($_GET['startTime'])!='' ? ' cdf.time_add >='.strtotime($_GET['startTime'].' 0:0:0 ') : '';
                $where[] = isset($_GET['endTime']) && trim($_GET['endTime'])!='' ? ' cdf.time_add <='.strtotime($_GET['endTime'].' 23:59:59 '): '';

                $where=array_filter ($where);
                $where = count($where)? ' and '.implode(' and ',$where):'';

                $stmt1 = DB::query('select count(id) count from cd_finance_details cdf where scan_type=4 '.$where);
                if($stmt1 && $stmt1->rowCount()) {

                    $data1 = $stmt1->fetch(\PDO::FETCH_ASSOC);
                    $count = $data1['count'];

                    if($count) {
                        // --- 判断分页 ---
                        $page = isset($_GET['page']) && trim($_GET['page']) != '' ? intval($_GET['page']) : 1;

                        \C\lib\Page::setParam($count, self::listRows, $page, 10);
                        \C\lib\Page::setConfig('prev', '<<');
                        \C\lib\Page::setConfig('next', '>>');
                        \C\lib\Page::setConfig('first', '首页');
                        \C\lib\Page::setConfig('last', '尾页');
                        \C\lib\Page::setConfig('theme', "共 %TOTAL_ROW% 条记录( %NOW_PAGE% / %TOTAL_PAGE% 页) %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");

                        $limit1 = ($page - 1) * self::listRows;

                        $stmt = DB::query('select cdf.id , cdw1.realname rname1 , price , cdw2.realname rname2 , cdf.time_add time_add from cd_finance_details cdf left join  cd_worker as cdw1 on cdf.worker_id=cdw1.id left join cd_worker as cdw2 on  cdf.worked_id=cdw2.id where scan_type=4 '.$where.' ORDER BY cdf.time_add DESC LIMIT '.$limit1.',' . self::listRows);


                        if($stmt && $stmt->rowCount()) {
                            $datas = [];
                            while($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                                $datas[] = $data;
                            }
                            $search['startTime'] = isset($_GET['startTime']) && trim($_GET['startTime'])!='' ? $_GET['startTime']: '';
                            $search['endTime']   = isset($_GET['endTime']) && trim($_GET['endTime'])!='' ? $_GET['endTime']: '';
                            $search = array_filter($search);

                            //充值总金额
                            $stmt = DB::query('select sum(price) total from cd_finance_details  where scan_type=4');
                            $total = 0;
                            if($stmt && $stmt->rowCount()) {
                                if($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                                    $total = $data['total'];
                                }
                            }

                            $this->render('finances/prepaidRecord', ['datas' => $datas, 'total'=>$total,  'myName'=>$worker->user, 'search'=>$search, 'pages' => \C\lib\Page::show()]);
                        }else
                            $this->render('finances/prepaidRecord', ['errors' => '查无充值记录失败']);
                    }else
                        $this->render('finances/prepaidRecord', ['errors' => '查无充值记录']);
                }else
                    $this->writeJson( 0 , '无询充值记录失败' ,1 );
            }else
                $this->writeJson( 0 , '无操作权限' ,1 );
        } else
            $this->writeJson( 0 , '请先登陆' ,1 );
    }
}


